import cv2
import matplotlib.pyplot as plt
from distributed.utils_comm import retry

def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
img_cat = cv2.imread('C:/Users/nic/Desktop/opencv/picture/cat.JPG',cv2.IMREAD_GRAYSCALE)


ret,thresh1 = cv2.threshold(img_cat,127,255,cv2.THRESH_BINARY)
ret,thresh2 = cv2.threshold(img_cat,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3 = cv2.threshold(img_cat,127,255,cv2.THRESH_TRUNC)
ret,thresh4 = cv2.threshold(img_cat,127,255,cv2.THRESH_TOZERO)
ret,thresh5 = cv2.threshold(img_cat,127,255,cv2.THRESH_TOZERO_INV)


titles = ['Original Image' , 'BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
images = [img_cat,thresh1,thresh2,thresh3,thresh4,thresh5]

for i in range(6):
    plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
    plt.title(titles[i])
    plt.xticks([]),plt.yticks([])
plt.show()
